package com.huashi.dealer.modular.controller.store.dashboard;

import cn.dev33.satoken.stp.StpUtil;
import com.huashi.dealer.core.pojo.CommonResult;
import com.huashi.dealer.core.util.SaTokenUtil;
import com.huashi.dealer.modular.controller.store.dashboard.param.StoreDashboardResponse;
import com.huashi.dealer.modular.controller.store.dashboard.service.StoreDashboardService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "门店后台-首页聚合接口")
@RestController
@RequestMapping("/store/dashboard")
@Validated
public class StoreDashboardController {

    @Resource
    private StoreDashboardService storeDashboardService;

    @GetMapping("/overview")
    @Operation(summary = "门店后台首页聚合数据")
    public CommonResult<StoreDashboardResponse> overview(
            @RequestParam(required = false) String startTime,
            @RequestParam(required = false) String endTime,
            @RequestParam(required = false, defaultValue = "50") Integer limit
    ) {
        Long storeUserId = SaTokenUtil.getLoginId();
        try {
            StoreDashboardResponse resp = storeDashboardService.getOverview(storeUserId, startTime, endTime, limit);
            return CommonResult.data(resp);
        } catch (Exception e) {
            return CommonResult.error("获取门店首页数据失败：" + e.getMessage());
        }
    }
}


